package cn.tedu.charging.order.rabbit;

import cn.tedu.charging.order.config.RabbitMqConfig;
import cn.tedu.charging.order.dao.mapper.ChargingSuccessMapper;
import cn.tedu.charging.order.dao.repository.OrderRepository;
import cn.tedu.charging.order.pojo.dto.OrderMqDTO;
import cn.tedu.charging.order.pojo.po.ChargingSuccessPO;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Slf4j
@Component
public class RabbitMqConsumer {
        @Autowired
        private OrderRepository OrderRepository;
        @RabbitListener(queues = RabbitMqConfig.DEAD_LETTER_QUEUE_NAME)
        public void consumerChargingQueue(OrderMqDTO orderMqDTO, Message message, Channel channel) throws IOException {
            log.debug("消费死信队列:{}",orderMqDTO);
            OrderRepository.updateOrderStatusFromProcess2Exception(orderMqDTO);

            // 自动确认ack
            long deliveryTag = message.getMessageProperties().getDeliveryTag();
            channel.basicAck(deliveryTag,true);
        }
}
